<template>
  <div class="largeScreen">
    <div class="headerBox">
      <div class="frc pt30 pr20">
        <div class="flc tabsBox">
          <div class="tabsItemBg cur f14 fcc flex-1" :class="tabIdx == idx ? 'selectTabsItemBg' : ''"
            v-for="(item, idx) in tablist" @click="tabsFun(idx)">
            <div>{{ item.name }}</div>
            <div class="down_line"></div>
          </div>
        </div>
        <div class="fcc">
          <div class="flc ml20">
            <div class="cblue">{{ currentDate }}</div>
            <div class="cwhite ml20">{{ currentTime }}</div>
            <div class="cblue"></div>
          </div>
        </div>
      </div>
        <!-- 添加光束元素 -->
      <div class="light-beam"></div>
    </div>

    <div class="fcbc chartBox p20">
      <div class="fcbc fv h1 flex-1 m-l-bg">
        <div class="mon-title f16 pl50 pt10 hand" @click="all()">全部电场</div>
        <div class="flt flex-1 w1 pt20 pl20">
          <el-tree class="w1" :data="treeData" :props="defaultProps" @node-click="handleNodeClick"
            node-key="id"></el-tree>
        </div>
      </div>
      <div class="fcbc fv h1 flex-4 m-r-bg">
        <div class="videoBox w1 h1 fcc fw"
          style="justify-content: flex-start; align-items: baseline;height: 100%;overflow: auto;">
          <div class="flc flex-1 flex4 p10" v-for="(item, idx) in cameraList" :key="idx" @click="goToDetail(item)">
            <div class="cameraItemBor w1 h1 cur">
              <div class=" flex-1 h1" :class="sfAll === '' ? 'cameraItemBox' : 'cameraItemBox1'">
                <div class="fcbc w1 cameraTitle">
                  <div class="cwhite">{{ item.label }}</div>
                </div>
                <div class="camera-time">点击查看详情</div>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { getLeft, rightList, rightListZ } from "@/api/dp/detection"
import axios from 'axios'
export default {
  name: "detection",
  data() {
    return {
      // 右侧数据
      cameraList: [],
      sfAll: '',
      currentDate: '',
      currentTime: '',
      zoomInCenter: false,
      tabIdx: 3,
      tablist: [
        {
          name: "全景监视",
          path: "/operation",
        },
        {
          name: "监控大屏",
          path: "/monitoring",
        },
        {
          name: "驾驶舱总览",
          path: "/cockpit",
        },
        {
          name: "数据监测",
          path: "/detection",
        },
        {
          name: "智能分析",
          path: "/analysis",
        },
      ],
      videoUrl: "https://www.runoob.com/try/demo_source/movie.mp4",
      treeData: [],
      defaultProps: {
        children: "children",
        label: "label",
      },
    };
  },
  methods: {
    // 点全部
    all() {
      let that = this;
      this.sfAll = 'Y'
      this.cameraList = []
      axios.get("/dev-api/system/farm/getlistFarm").then(response => {
        response.data.rows.forEach(key => {
          let row = {
            id: key.windFarmId,
            parentId: null,
            label: key.name,
            windFarmId: key.windFarmId
          }
          that.cameraList.push(row)
        })
      })
    },
    leftTree() {
      getLeft().then(response => {
        this.treeData = response.data
      })
    },
    // 年月日时分秒
    updateDateTime() {
      const now = new Date();
      // 格式化日期（YYYY-MM-DD 星期X）
      const weekdays = ['星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六'];
      const year = now.getFullYear();
      const month = String(now.getMonth() + 1).padStart(2, '0');
      const day = String(now.getDate()).padStart(2, '0');
      const weekday = weekdays[now.getDay()];
      this.currentDate = `${year}-${month}-${day} ${weekday}`;

      // 格式化时间（HH:MM:SS）
      const hours = String(now.getHours()).padStart(2, '0');
      const minutes = String(now.getMinutes()).padStart(2, '0');
      const seconds = String(now.getSeconds()).padStart(2, '0');
      this.currentTime = `${hours}:${minutes}:${seconds}`;
    },
    tabsFun(i) {
      this.tabIdx = i;
      this.$router.push(this.tablist[i].path);
    },
    handleNodeClick(data) {
      this.sfAll = ''
      if (data.code == undefined) {
        rightListZ(data.id).then(response => {
          this.cameraList = response.data
        })
      } else {
        rightList(data.id).then(response => {
          this.cameraList = response.data
        })
      }
    },
    goToDetail(row) {
      if (row.parentId) {
        this.$router.push({path: "/fengJiDetail",
          query: {
            windTurbineId: row.id,       // 第一个参数
            windTurbinename: row.label    // 第二个参数
          }
        });
      } else {
        this.$router.push({path: "/dianchangDetail?windFarmId="+row.windFarmId});
      }
    },

      // 增强版数据刷新方法
      async refreshData() {
      try {
        await Promise.all([
          this.sfAll = 'Y',
          this.all(),
          // 左侧树
          this.leftTree()
        ]);
        console.log('数据刷新成功', new Date().toLocaleString());
      } catch (error) {
        console.error('数据刷新失败:', error);
      }
    },
    
    // 初始化定时器
    initRefreshTimer() {
      // 先清除旧定时器
      if (this.refreshInterval) {
        clearInterval(this.refreshInterval);
      }
      
      // 设置定时器 (1分钟)
      this.refreshInterval = setInterval(() => {
        this.refreshData();
      }, 60000);
    }
  },
  mounted() {
    // 初始化定时刷新
    this.initRefreshTimer();


    this.sfAll = 'Y'
    this.all()
    // 左侧树
    this.leftTree()
    // 初始更新
    this.updateDateTime();

    // 每秒更新一次
    this.timer = setInterval(this.updateDateTime, 1000);
  },
  beforeDestroy() {
    // 清除定时器，防止内存泄漏
    clearInterval(this.timer);
  }
};
</script>

<style scoped lang="scss">
.largeScreen {
  width: 100%;
  height: 100%;
  background-color: #000f21;
  position: relative;
}

.headerBox {
  background-image: url("~@/assets/images/windPower/titleMax.png");
  background-size: 100% 100%;
  height: 84px;
  min-height: 84px;
  max-height: 84px;
  width: 100%;
  position: relative;
  z-index: 99;
  overflow: hidden; /* 确保光束不会溢出 */
  /* 光束元素样式 */
.light-beam {
  position: absolute;
  top: 0;
  left: -80%; /* 初始位置在左侧外部 */
  width: 100px;
  height: 3px;
  background: linear-gradient(to left, 
              #ffffff, 
              rgba(255,255,255,0.8),
              rgba(255,255,255,0.5),
              rgba(255,255,255,0.2),
              transparent);

  transform: skewX(-20deg); /* 使光束倾斜 */
  animation: beam-scan 5s linear infinite;
  z-index: 1;
}

/* 光束动画 */
@keyframes beam-scan {
  0% {
    left: -50%;
    opacity: 0;
    top: 63px;
  }
  20% {
    opacity: 0.8;
    top: 63px;
  }
  40% {
    opacity: 0.8;
    top: 63px;
  }
  43% {
    opacity: 0;
    top: 63px;

  }
  46% {
    opacity: 0;
    top: 63px;

  }
  47% {
    opacity: 0.8;
    top: 15px;
  }
  80% {
    opacity: 0.8;
    top: 15px;
  }
  90% {
    opacity: 0.8;
    top: 15px;
  }
  100% {
    left: 100%;
    opacity: 0;
    top: 15px;
  }
}

/* 确保标题内容在光束之上 */
.headerBox > * {
  position: relative;
  z-index: 2;
}

  .tabsBox {
    width: 45%;

    .tabsItemBg {
      background-image: url("~@/assets/images/windPower/tabs.png");
      background-size: 100% 100%;
      height: 40px;
      color: #45a2ff;
      position: relative;

      .down_line {
        display: none;
        position: absolute;
        background-image: url("~@/assets/images/windPower/select-tabs.png");
        background-size: 100% 100%;
        width: 80%;
        height: 33px;
        top: 22px;
      }
    }

    .tabsItemBg:hover {
      color: #ffffff;

      .down_line {
        display: block;
      }
    }

    .selectTabsItemBg {
      color: #ffffff;

      .down_line {
        display: block;
      }
    }
  }
}

.cblue {
  color: #45a2ff;
}

.cwhite {
  color: #ffffff;
}

.cgray {
  color: #999999;
}

.chartBox {
  height: calc(100% - 84px);
  position: relative;
  z-index: 1;

  .chartTile {
    color: #ffffff;
    background-image: url("~@/assets/images/windPower/titleMin.png");
    background-size: 100% 100%;
    height: 40px;
    width: 100%;
    font-weight: bold;
  }

  .icon-electricity {
    color: #0aa7ff;
    background-image: url("~@/assets/images/icon/icon-electricity.png");
    background-size: 100% 100%;
    height: 50px;
    width: 50px;
  }
}

.mon-title {
  background: url("~@/assets/images/windPower/m-title.png");
  background-size: 100% 100%;
  width: 100%;
  height: 40px;
  color: #ffffff;
}

.m-l-bg {
  background: url("~@/assets/images/windPower/m-l-bg.png");
  background-size: 100% 100%;
}

.hand {
  cursor: pointer;
}

.m-r-bg {
  background: url("~@/assets/images/windPower/m-bg.png");
  background-size: 100% 100%;
}

.videoBox {
  position: relative;
  margin: 35px 0;
  padding: 0 20px;

  .videoTitle {
    padding: 5px 10px;
    background-color: #1b7ef280;
  }

  .cameraItemBor {
    background: url("~@/assets/images/windPower/cameraBor.png");
    background-size: 100% 100%;
    padding: 10px;
  }

  .cameraItemBox {
    background: url("~@/assets/images/windPower/detectionBg2.png");
    background-size: 100% 100%;
  }

  .cameraItemBox1 {
    background: url("~@/assets/images/windPower/detectionBg.png");
    background-size: 100% 100%;
  }

  .cameraTitle {
    background: url("~@/assets/images/windPower/cameraTitle.png");
    background-size: 100% 100%;
    padding: 5px 10px;
  }

  .flex4 {
    flex: 0 0 25%;
    height: 33.33%;
  }

  .fullScreenBox {
    position: absolute;
    top: 0;
    left: 0;
    // margin:45px 40px;
  }
}

::v-deep .el-tree {
  background: transparent;
  color: #ffffff;
}

::v-deep .el-tree-node__content:hover {
  background: linear-gradient(to right, #1b7ef2, #1b7ef200);
}

::v-deep .el-tree-node:focus>.el-tree-node__content {
  background: linear-gradient(to right, #1b7ef2, #1b7ef200);
}

::v-deep .el-carousel__container {
  height: 100%;
}

::v-deep .el-carousel__indicators {
  display: none;
}

/* 添加时间样式 */
.camera-time {
  position: absolute;
  right: 10px;
  bottom: 10px;
  color: #ffffff;
  font-size: 12px;
  background-color: transparent;
  padding: 2px 5px;
  border-radius: 3px;
}

.cameraItemBor {
  position: relative;
  /* 使时间定位生效 */
}
</style>
